'use strict'
const mssql = require('mssql')
const config = require('./dbconfig')
var db = {}


db.find = function (queryString){
     
    console.log(queryString)
    
    return new Promise(function(resovle,reject){
        const pool = new mssql.ConnectionPool(config,err => {
            if(err){ console.log(err)}
            pool.request() // or: new sql.Request(pool1)
            //.input('queryString', sql.Int, 10)
            .query(queryString, (err, result) => {
                
                resovle(result)
                pool.close()
            })
         
        })
        pool.on('error', err => {
            new Error(err)
        })
        
    })
    
} 


 

db.insert = function (params){
    return new Promise(function(resovle, reject) {
        const pool = new sql.ConnectionPool(config,err => {
            if(err){ console.log(err)}
            pool.request() // or: new sql.Request(pool1)
            //.input('queryString', sql.Int, 10)
            .query('insert into user_infor set ?', params, (err, result) => {
                console.log(result);
                resovle(result)
                pool.close()
            })
         
        })
    })
        
}
 


 function dbclose (){
    return sql.close()
}

module.exports = db;  